package geometric3D;

public class xLineSegment extends LineSegment {
	
	public xLineSegment(Point startPoint, int length,
			boolean isPositiveProjected) {
		super(length);
		if(isPositiveProjected){
			this.startPoint = startPoint;
			this.endPoint = new Point(startPoint.getX()+length, 
					startPoint.getY(), 
					startPoint.getZ());
		}else{
			this.endPoint = startPoint;
			this.startPoint = new Point(startPoint.getX()-length, 
					startPoint.getY(), 
					startPoint.getZ());
		}

	}


	public xLineSegment(Point startPoint, Point endPoint){
		
		if(startPoint.getX()>endPoint.getX()){
			this.startPoint = endPoint;
			this.endPoint = startPoint;
		}else{
			this.startPoint = startPoint;
			this.endPoint = endPoint;
		}
		
		this.length = Math.abs(startPoint.getX()-endPoint.getX());
		
		
	}
	@Override
	public Point getEndPoint() {
		return this.endPoint;
	}

	@Override
	public String toString() {
		return "xLineSegment [startPoint=" + startPoint + ", endPoint="
				+ endPoint + ", length=" + length + "]\n";
	}


	@Override
	public Point getStartPoint() {
		return this.startPoint;
		
	}


	@Override
	public boolean isInLineSegment(Point point) {
		if(point.getY() != startPoint.getY() 
				|| point.getZ() != startPoint.getZ()
				|| point.getX() < startPoint.getX()
				|| point.getX()> endPoint.getX()){
			return false;
		}
		return true;
	}


}
